﻿@model KL.Store.Web.Models.ProductModel
@using KL.Store.Core
@{
    Layout = null;
    var variantListClass = Parameters.ShowVariantsAsRadio ? "variantList RadioSelection" : "variantList";
}
@if (!Model.CheckStock || Parameters.AllowEndedProducts || Model.InStockDepo > 0)
{
    if (Parameters.Theme == "HA" || Parameters.Theme == "WU")
    {
    <div class="cart">
        <div class="cart-top-padd">
            @if (Model.variantPropertiesList.Count() >= 1)
            {
                <div class="@variantListClass">
                    @if (Parameters.ShowVariantsAsRadio)
                    {
                        <ul>
                            @foreach (var variant in Model.variantPropertiesList)
                            {
                                <li @{if (ViewBag.SelectedVariant == variant.id)
                                      {<text>class="selectedVariantRadio"</text>}}>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="variantProduct" value="@variant.productId" id="variant@(variant.id)" data-id="@(variant.id)" data-url="@(variant.LinkUrl)" data-value="@(variant.value)" data-productname="@(variant.ProductName + (!string.IsNullOrEmpty(variant.Model) ? " - " + variant.Model : ""))"  @{if (ViewBag.SelectedVariant == variant.id)
                                                                                                                                                                                                                                                                                                                                                  {<text>checked="checked"</text>}}>
                                            @variant.value
                                        </label>
                                    </div>
                                </li>
                            }
                        </ul>
                        <div class="clearfix"></div>
                    }
                    else
                    {
                        <select name="variantProduct">
                            @foreach (var variant in Model.variantPropertiesList)
                            {
                                <option value="@variant.productId" data-id="@variant.id" @{if (ViewBag.SelectedVariant == variant.id)
                                                                                           {<text>selected="selected"</text>}}>@variant.value</option>
                            }
                        </select>
                    }
                </div>
            }
            <div class="qtilabel">
                <label>Adet</label>
            </div>
            <div class="qtitext">
                <input type="text" maxlength="2" class="input-qti" value="1" size="2" id="qty_@Model.ProductId" />
            </div>
            <div class="qtibuttons">
                <input type="button" onclick="qtyAdd();" class="plus" id="add1" />
                <input type="button" onclick="qtyMinus();" class="minus" id="minus1" />
                <input type="hidden" value="@(Model.ProductId)" name="productId" />
            </div>
            <div class="qtiinstallmentneeded">
                @if (Model.InstallmentNeeded)
                {
                    <input id="InstallmentSelected" type="checkbox" name="InstallmentSelected" data-val-required="InstallmentSelected alanı gereklidir.">
                    <label class="InstallmentSelectedText" for="InstallmentSelected">
                        Kurulum İstiyorum
                     @if (Model.InstallmentPrice > 0)
                     {
                         <span>(@Model.InstallmentPrice.ToString("###,###,##0.00")
                             @(Model.Currency))</span>
                     }
                    </label>
                    <div class="clearfix"></div>
                }
            </div>
            @if (Parameters.UseWishList)
            {
                <a class="addToCart" id="in_@Model.ProductId"><span class="sepet-icon"></span><span class="sepet-text">SEPETE EKLE</span></a>

                <a class="addTooltip" id="prd_@Model.ProductId" onclick="addToWishList('@(Model.ProductId)');" title="Listeme Ekle">
                    <span class="sepet-icon"></span><span class="sepet-text">LİSTEME EKLE</span></a>

            }
            else
            {
                <a class="addToCart" id="in_@Model.ProductId"><span class="sepet-icon"></span><span class="sepet-text">SEPETE EKLE</span></a>
            }
            <a class="orderNow" id="ord_@Model.ProductId"><span class="ord-text">HEMEN AL</span></a>
            @if (!string.IsNullOrEmpty(Parameters.FreeCitiesHtml) && (Model.FreeCargoInCity || (Model.InstallmentNeeded && Model.FreeInstallmentInCity)))
            {
                <div class="freeCCI bg-info bs-bgb">
                    <div>
                        <span class="glyphicon glyphicon-info-sign"></span>
                        @if (Model.FreeCargoInCity && (Model.FreeInstallmentInCity && Model.InstallmentNeeded))
                        {
                            <text>Kargo ve Kurulumun Ücretsiz Olduğu Şehirler:</text>
                        }
                        else if (Model.FreeCargoInCity)
                        {
                            <text>Kargonun Ücretsiz Olduğu Şehirler:</text>
                        }
                        else if (Model.FreeInstallmentInCity)
                        {
                            <text>Kurulumun Ücretsiz Olduğu Şehirler:</text>
                        }
                    </div>
                    @Html.Raw(Parameters.FreeCitiesHtml)
                    <div class="clearfix"></div>
                </div>
                <div class="clearfix"></div>
            }
        </div>
    </div>
    }
    else
    {
    <div class="cart">
        <div class="cart-basket"></div>
        <div class="cart-top">
            <div class="cart-top-padd">
                <label>Adet:</label>
                <input type="button" onclick="qtyMinus();" class="minus" id="minus1" />
                <input type="text" maxlength="2" class="input-qti" value="1" size="2" id="qty_@Model.ProductId" />
                <input type="button" onclick="qtyAdd();" class="plus" id="add1" />
                <input type="hidden" value="@(Model.ProductId)" name="productId" />
            </div>
            <div class="extra-button">
                @if (Parameters.UseWishList)
                {
                    <div class="left">
                        <a class="addToCart addTooltip" id="in_@Model.ProductId" title="Sepete Ekle">
                            <img src="/Images/@(Parameters.Theme)/urun-hover-sepet.png" height="25" /></a>
                    </div>                            
                    <div class="left" style="margin-left: 5px;">
                        <a class="addTooltip" id="prd_@Model.ProductId" onclick="addToWishList('@(Model.ProductId)');" title="Listeme Ekle" >
                            <img src="/Images/@(Parameters.Theme)/urun-hover-list.png" height="25" /></a>
                    </div>
                }
                else
                {
                    <div>
                        <a class="addToCart" id="in_@Model.ProductId">Sepete At</a>
                    </div>
                }
            </div>
        </div>
    </div>
    <button class="orderNow" id="ord_@Model.ProductId">Hemen Al</button>
    <div class="clearfix"></div>
                if (Model.InstallmentNeeded)
                {
    <div class="installment-needed">
        @Html.CheckBoxFor(m => m.InstallmentSelected)
        <label class="InstallmentSelectedText" for="InstallmentSelected">
            Kurulum İstiyorum
                     @if (Model.InstallmentPrice > 0)
                     {
                         <text>(</text><span class="installment-needed-price">@Model.InstallmentPrice.ToString("###,###,##0.00")</span>
                         <span class="installment-needed-tax">@(Model.Currency)(KDV Dahil)</span><text>)</text>
                     }

        </label>
    </div>
    <div class="clearfix"></div>
                }
                if (!string.IsNullOrEmpty(Parameters.FreeCitiesHtml) && (Model.FreeCargoInCity || (Model.InstallmentNeeded && Model.FreeInstallmentInCity)))
                {
    <div class="freeCCI bg-info bs-bgb">
        <div>
            <span class="glyphicon glyphicon-info-sign"></span>
            @if (Model.FreeCargoInCity && (Model.FreeInstallmentInCity && Model.InstallmentNeeded))
            {
                <text>Kargo ve Kurulumun Ücretsiz Olduğu Şehirler:</text>
            }
            else if (Model.FreeCargoInCity)
            {
                <text>Kargonun Ücretsiz Olduğu Şehirler:</text>
            }
            else if (Model.FreeInstallmentInCity)
            {
                <text>Kurulumun Ücretsiz Olduğu Şehirler:</text>
            }
        </div>
        @Html.Raw(Parameters.FreeCitiesHtml)
        <div class="clearfix"></div>
    </div>
    <div class="clearfix"></div>
                }
    }
}
else
{
    <div class="variantList">
        <label style="color: #e11; font-size: 14px;">Ürün Tükendi!</label><label style="font-size: 14px; color: #444; font-weight: normal; margin-left: 7px;">İlginiz için teşekkürler...</label>
    </div>
    <div class="clearfix"></div>
}
<script>
    var ps = new Array();
    var pm = new Array();
    @foreach (var varUrl in Model.variantUrlsList)
    {
        <text>ps['@(varUrl.ProductId)'] = '@(varUrl.ProductName)';</text>
        <text>pm['@(varUrl.ProductId)'] = '@(varUrl.Model)';</text>
    }
    //$(document).ready(function ()
    //{
    //   $(".productAddToCart").load('/Product/ProductAddToCart', { id: $("select[name=variantProduct]").val(), selectedVariant: '@ViewBag.SelectedVariant', pRelPos: '@ViewBag.productRelatedsPosition' });
    //    $("#product-view-prices-div").load('/Product/ProductPrices', { id: $("select[name=variantProduct]").val(), pRelPos: '@ViewBag.productRelatedsPosition' });
    //});
    $(".product-review-main select[name=variantProduct]").change(function ()
    {
        ChangeVariant($(this).val(), $(this).find(':selected').data('id'), '@ViewBag.productRelatedsPosition', 'productView');
    });
    $(".product-review-main input[name=variantProduct]").click(function ()
    {
        ChangeVariant($(this).val(), $(this).data('id'), '@ViewBag.productRelatedsPosition', 'productView');
    });

    $("#quickViewContainer select[name=variantProduct]").change(function ()
    {
        ChangeVariant($(this).val(), $(this).find(':selected').data('id'), '@ViewBag.productRelatedsPosition', 'quickView');
    });
    $("#quickViewContainer input[name=variantProduct]").click(function ()
    {
        ChangeVariant($(this).val(), $(this).data('id'), '@ViewBag.productRelatedsPosition', 'quickView');
    });
    function ChangeVariant(variantId, selectedVariantId, variantpRelPos, adcPos)
    {
        if (adcPos == 'quickView')
        {
            $("#quickViewContainer .product-titles h1").html(ps[variantId]);
            if (pm[variantId] != '')
            {
                $("#quickViewContainer .product-model").html("<strong>Model :</strong> " + pm[variantId]);
            }
            $("#quickViewContainer #product-view-prices-div").load('/Product/ProductPrices', { id: variantId, pRelPos: variantpRelPos });
            $("#quickViewContainer .productAddToCart").load('/Product/ProductAddToCart', { id: variantId, selectedVariant: selectedVariantId, pRelPos: variantpRelPos });
            $("#quickViewContainer .discountOuter").load('/Product/ProductDiscount', { id: variantId });
            if ($('#quickViewContainer .slides .not-clone').hasClass('productImage' + variantId))
            {
                var imgIndex = $('#quickViewContainer li.not-clone.productImage' + variantId).not('.clone').first().index();
                var clnIndex = $('#quickViewContainer li.not-clone.productImage' + variantId).first().index();
                imgIndex = imgIndex - 1;
                var flSlider = $('#quickViewContainer #slider').data('flexslider');
                flSlider.flexAnimate(imgIndex);
            }
        }
        else
        {
            //alert(selectedVariantId + ' / ' + ps[variantId]);
            $(".product-review-main .product-titles h1").html(ps[variantId]);
            if (pm[variantId] != '')
            {
                $(".product-review-main .product-model").html("<strong>Model :</strong> " + pm[variantId]);
            }
            $(".product-review-main #product-view-prices-div").load('/Product/ProductPrices', { id: variantId, pRelPos: variantpRelPos });
            $(".product-review-main .productAddToCart").load('/Product/ProductAddToCart', { id: variantId, selectedVariant: selectedVariantId, pRelPos: variantpRelPos });
            $(".installmentsTablePlaceHolder").load('/Product/ProductInstallmentsTable', { id: variantId });
            $(".product-review-main .discountOuter").load('/Product/ProductDiscount', { id: variantId });
            $(".productDescription").load('/Product/ProductDescription', { id: variantId });
            if ($('.product-review-main .slides .not-clone').hasClass('productImage' + variantId))
            {
                var imgIndex = $('.product-review-main li.not-clone.productImage' + variantId).not('.clone').first().index();
                var clnIndex = $('.product-review-main li.not-clone.productImage' + variantId).first().index();
                imgIndex = imgIndex - 1;
                var flSlider = $('.product-review-main #slider').data('flexslider');
                flSlider.flexAnimate(imgIndex);
            }
            var selected = $('#variant' + selectedVariantId);
            PushUrl(selected.data('name'), selected.data('url'));
        }
    }




</script>
<script>
    $('.product-review-main a.addToCart').unbind("click");
    $('#quickViewContainer a.addToCart').unbind("click");

    $('.product-review-main a.addToCart').click(function ()
    {
        $('body,html').animate({
            scrollTop: 0
        }, 800);
        var qsId = $(this).attr('id').split("_")[1];
        var qty = $('.product-review-main #qty_' + qsId.toString()).val();
        var ins = $('.product-review-main #InstallmentSelected').attr('checked') ? "True" : "False";
        var vval = "";
        if ($('.product-review-main select[name=variantProduct]').length > 0)
        {
            vval = $('.product-review-main select[name=variantProduct] option:selected').text();
        }
        else if ($('.product-review-main input[name=variantProduct]').length > 0)
        {
            vval = $('.product-review-main input[name=variantProduct]:checked').data('value');
        }
        if ('@Model.InstallmentNeeded' == 'True' && ins == 'False')
        {
            var answer = confirm("Kurulum isteği olmadan işleme devam edilsin mi?")
            if (!answer)
            {
                return false;
            }
        }
        $('#cart').delay(800).load('/Cart/Insert', { id: qsId, qty: qty, installment: ins, variantValue: vval });
        $(".sepetFull img").delay(800).fadeOut("slow").fadeIn("slow");
        $('#sepetMinimalContent').load('/Cart/GetMinimal', { showPhotos: true, ShowAcrIcrLinks: true });
        return false;
    });
    $('#quickViewContainer a.addToCart').click(function ()
    {
        $('body,html').animate({
            scrollTop: 0
        }, 800);
        var qsId = $(this).attr('id').split("_")[1];
        var qty = $('#quickViewContainer #qty_' + qsId.toString()).val();
        var ins = $('#quickViewContainer #InstallmentSelected').attr('checked') ? "True" : "False";
        var vval = "";
        if ($('#quickViewContainer select[name=variantProduct]').length > 0)
        {
            vval = $('#quickViewContainer select[name=variantProduct] option:selected').text();
        }
        if ('@Model.InstallmentNeeded' == 'True' && ins == 'False')
        {
            var answer = confirm("Kurulum isteği olmadan işleme devam edilsin mi?")
            if (!answer)
            {
                return false;
            }
        }
        $('#cart').delay(800).load('/Cart/Insert', { id: qsId, qty: qty, installment: ins, variantValue: vval });
        $(".sepetFull img").delay(800).fadeOut("slow").fadeIn("slow");
        $('#sepetMinimalContent').load('/Cart/GetMinimal', { showPhotos: true, ShowAcrIcrLinks: true });
        return false;
    });
    if (typeof qtyAdd == 'undefined' || !$.isFunction(qtyAdd))
    {
        function qtyAdd(productIdQty)
        {
            var q = $('#qty_@(Model.ProductId)').val();
            if (q < 99)
            {
                q++;
                $('#qty_@(Model.ProductId)').val(q);
            }
        }
    }
    if (typeof qtyMinus == 'undefined' || !$.isFunction(qtyMinus))
    {
        function qtyMinus(productIdQty)
        {
            var q = $('#qty_@(Model.ProductId)').val();
            if (q > 1)
            {
                q--;
                $('#qty_@(Model.ProductId)').val(q);
            }
        }
    }

    $('.orderNow').click(function ()
    {
        var qsId = $(this).attr('id').split("_")[1];
        var qty = $('#qty_' + qsId.toString()).val();
        var ins = $('#InstallmentSelected').attr('checked') ? "True" : "False";
        var vval = "";
        if ($('select[name=variantProduct]').length > 0)
        {
            vval = $('select[name=variantProduct] option:selected').text();
        }
        if ('@Model.InstallmentNeeded' == 'True' && ins == 'False')
        {
            var answer = confirm("Kurulum isteği olmadan işleme devam edilsin mi?")
            if (!answer)
            {
                return false;
            }
        }
        $('#cart').load('/Cart/Insert', { id: qsId, qty: qty, installment: ins, variantValue: vval }, function() {
            window.location.href = "/Cart/Checkout";
        });
        return false;
    });
</script>
